﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Noria.Web.MyMSDN;
using Noria.Web.MyMSDN.Models;
using Noria.Web.MyMSDN.Workers;
using Noria.Web.Utility;

namespace Noria.Web.Test
{
    [TestClass]
    public class MsdnWorkerTest
    {
        private static readonly string rootMSDN = (string)NConfig.Root.spider.settings.msdn;

        private static readonly string urlCategory = rootMSDN + "/en-us/subscriptions/json/GetProductCategories?brand=MSDN&localeCode=en-us";
        private static readonly string urlFamily = rootMSDN + "/en-us/subscriptions/json/GetProductFamiliesForCategory?brand=MSDN&categoryId={0}";
        private static readonly string urlSearch = rootMSDN + "/en-us/subscriptions/json/GetFileSearchResult";


        [TestMethod]
        public void GetCategoryMethod()
        {
            using (var stat = new SimpleStatistics("msdn.test"))
            {
                ((MsdnWorker)MsdnWorker.Create(stat, new AsyncWaiter())).GetCategory(true);
            }
        }

        [TestMethod]
        public void GetFamilyMethod()
        {
            using (var stat = new SimpleStatistics("msdn.test"))
            {
                ((MsdnWorker)MsdnWorker.Create(stat, new AsyncWaiter())).GetFamily(true);
            }
        }

        [TestMethod]
        public void GetFileMethod()
        {
            using (var stat = new SimpleStatistics("msdn.test"))
            {
                ((MsdnWorker)MsdnWorker.Create(stat, new AsyncWaiter())).GetFile(true);
            }
        }

        [TestMethod]
        public void GetFilePagingMethod()
        {
            using (var stat = new SimpleStatistics("msdn.test"))
            {
                var worker = new MsdnFileWorker(urlSearch);

                var family = new Family
                    {
                        FamilyId = 350,
                        Name = "Windows 7",
                        CategoryId = 36
                    };
                worker.RetrieveFileListByFamily(stat, new AsyncWaiter(), family);
                worker.Save(stat, family.Files);
            }
        }

        [TestMethod]
        public void GetAll()
        {
            using (var stat = new SimpleStatistics("msdn.test"))
            {
                MsdnWorker.Create(stat, new AsyncWaiter()).Work();
            }
        }
    }

    public class MockStatistics : IStatistics
    {
        public void Dispose()
        {

        }

        public void AddHttp(long latency, long payload)
        {
        }

        public long GetCount()
        {
            return 0;
        }

        public long GetLatency()
        {
            return 0;
        }

        public long GetPayload()
        {
            return 0;
        }

        public void Cancel()
        {

        }

        public void Fault()
        {

        }

        public void AddUpdated()
        {

        }

        public void AddInserted()
        {

        }

        public void AddDeleted()
        {

        }

        public void AddError()
        {

        }
    }
}
